/**禁用 */
export function formatEnable(val: number) {
  if (isNil(val)) return '-'
  return (
    new Map([
      [1, '启用'],
      [2, '禁用']
    ]).get(val) || val
  )
}

/**NS状态 */
export function formatNSStatus(val: number) {
  if (isNil(val)) return '-'
  return (
    new Map([
      [1, '正常'],
      [2, '异常']
    ]).get(val) || val
  )
}

/**解析状态 */
export function formatResolveStatus(val: number) {
  if (isNil(val)) return '-'
  return (
    new Map([
      [1, '正常'],
      [2, '暂停']
    ]).get(val) || val
  )
}

export function _userMailEll(value: string) {
  const getStr = (str: string, start: number) =>
    `${str.substring(0, start)}***${str.substring(
      str.length - start,
      str.length
    )}`

  if (value.length > 6) {
    return getStr(value, 3)
  }
  if (value.length > 4) {
    return getStr(value, 2)
  }
  if (value.length > 2) {
    return getStr(value, 1)
  }
  if (value.length < 2 && value.length > 0) {
    return `${value.substring(0, 1)}***`
  }
  return '-'
}

/**用户名/邮箱加 ‘*’ */
export function userMailEll(value: string) {
  if (!value) return '-'
  // 是否是邮箱
  const reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
  let prefix = ''
  let res = ''
  const isEmail = reg.test(value)
  if (isEmail) {
    const split = value.split('@')
    prefix = split[0]
    const suffix = split[1]
    res = _userMailEll(prefix) + '@' + suffix
  } else {
    res = _userMailEll(value)
  }
  return res
}
